package com.whm.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.whm.common.annotation.Log;
import com.whm.common.core.controller.BaseController;
import com.whm.common.core.domain.AjaxResult;
import com.whm.common.enums.BusinessType;
import com.whm.system.domain.BWorkDaily;
import com.whm.system.service.IBWorkDailyService;
import com.whm.common.utils.poi.ExcelUtil;
import com.whm.common.core.page.TableDataInfo;

/**
 * 工作日报Controller
 * 
 * @author ruoyi
 * @date 2023-12-24
 */
@RestController
@RequestMapping("/system/daily")
public class BWorkDailyController extends BaseController
{
    @Autowired
    private IBWorkDailyService bWorkDailyService;

    /**
     * 查询工作日报列表
     */
    @PreAuthorize("@ss.hasPermi('system:daily:list')")
    @GetMapping("/list")
    public TableDataInfo list(BWorkDaily bWorkDaily)
    {
        startPage();
        List<BWorkDaily> list = bWorkDailyService.selectBWorkDailyList(bWorkDaily);
        return getDataTable(list);
    }

    /**
     * 导出工作日报列表
     */
    @PreAuthorize("@ss.hasPermi('system:daily:export')")
    @Log(title = "工作日报", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BWorkDaily bWorkDaily)
    {
        List<BWorkDaily> list = bWorkDailyService.selectBWorkDailyList(bWorkDaily);
        ExcelUtil<BWorkDaily> util = new ExcelUtil<BWorkDaily>(BWorkDaily.class);
        util.exportExcel(response, list, "工作日报数据");
    }

    /**
     * 获取工作日报详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:daily:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bWorkDailyService.selectBWorkDailyById(id));
    }

    /**
     * 新增工作日报
     */
    @PreAuthorize("@ss.hasPermi('system:daily:add')")
    @Log(title = "工作日报", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BWorkDaily bWorkDaily)
    {
        bWorkDaily.setCreateBy(getUsername());
        return toAjax(bWorkDailyService.insertBWorkDaily(bWorkDaily));
    }

    /**
     * 修改工作日报
     */
    @PreAuthorize("@ss.hasPermi('system:daily:edit')")
    @Log(title = "工作日报", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BWorkDaily bWorkDaily)
    {
        bWorkDaily.setUpdateBy(getUsername());
        return toAjax(bWorkDailyService.updateBWorkDaily(bWorkDaily));
    }

    /**
     * 删除工作日报
     */
    @PreAuthorize("@ss.hasPermi('system:daily:remove')")
    @Log(title = "工作日报", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bWorkDailyService.deleteBWorkDailyByIds(ids));
    }
}
